/* 
 * RoomDaoConverter.java 29.03.2011
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */
package suncertify.util;

import suncertify.dao.RoomRecord;

/**
 * @author Alessandra
 * 
 */
public class RoomConverter {

    /**
     * <br>
     * 1: name <br>
     * 2: location <br>
     * 3: size <br>
     * 4: smoking <br>
     * 5: rate <br>
     * 6: date <br>
     * 
     * @param room
     * @return Array with record data
     */
    public static String[] roomAsArray(RoomRecord room) {
	String[] roomArray = new String[7];

	roomArray[0] = room.getName();
	roomArray[1] = room.getLocation();
	roomArray[2] = room.getSize() + "";
	roomArray[3] = room.getSmoking();
	roomArray[4] = room.getRate();
	roomArray[5] = room.getDate();
	roomArray[6] = room.getOwner();
	
	return roomArray;
    }

    /**
     * <br>
     * 1: name <br>
     * 2: location <br>
     * 3: size <br>
     * 4: smoking <br>
     * 5: rate <br>
     * 6: date <br>
     * 7: owner <br>
     * 
     * @param roomArray
     * @return RoomDao
     */
    public static RoomRecord arrayAsRoom(String[] roomArray) {
	RoomRecord room = new RoomRecord();

	room.setName(roomArray[0]);
	room.setLocation(roomArray[1]);
	String size = roomArray[2];
	if (!"".equals(size.trim())) {
	    room.setSize(Integer.parseInt(size.trim()));
	}
	room.setSmoking(roomArray[3]);
	room.setRate(roomArray[4]);
	room.setDate(roomArray[5]);
	room.setOwner(roomArray[6]);

	return room;
    }
}
